$(document).ready(function() {
		//外部js调用
    laydate({
        elem: '#startTime', //需显示日期的元素选择器
		event: 'focus', //触发事件
		format: 'YYYY-MM-DD hh:mm:ss', //日期格式
		istime: true, //是否开启时间选择
		isclear: true, //是否显示清空
		istoday: true, //是否显示今天
		issure: true, //是否显示确认
		festival: true, //是否显示节日
		min:'1900-01-01 00:00:00',//最小日期
		max:'2099-12-31 23:59:59',//最大日期
		start:laydate.now(),    //开始日期
		key:'2017-01-17 23:22:59'
		//choose: function(dates){} //选择好日期的回调
    });    
    //外部js调用
    laydate({
        elem: '#endTime', //需显示日期的元素选择器
		event: 'focus', //触发事件
		format: 'YYYY-MM-DD hh:mm:ss', //日期格式
		istime: true, //是否开启时间选择
		isclear: true, //是否显示清空
		istoday: true, //是否显示今天
		issure: true, //是否显示确认
		festival: true, //是否显示节日
		min:'1900-01-01 00:00:00',//最小日期
		max:'2099-12-31 23:59:59',//最大日期
		start:laydate.now(),    //开始日期
		key:'2017-01-17 23:22:59'
		//choose: function(dates){} //选择好日期的回调
    });
	//初始化数据
	init(1);
});

function init(pageNo){
	var userId = getvl("shopId");
	var value=getvl("value");
	var startTime = $('#startTime').val();
	var endTime = $('#endTime').val();
	$("#thislist").html("");
	$.ajax({
		url: urlcore + "/api/cashRecord/cashRecordDisplay2?userId="+userId+"&pageNum="+pageNo+"&pageSize="+pageSize+"&value="+value+"&startTime="+ startTime +"&endTime="+ endTime,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				//i表示在data中的索引位置，n表示包含的信息的对象
				$.each(data.data.list,function(i,n){
					var id = n.id;
					var recoedType2 = recoedTypeStr(n.recoedType);
					var moneyType2 = moneyTypeStr(n.moneyType);	
					var thislist =
					'	<tr>'+
					'		<td>'+(i+1)+'</td>'+
					'		<td>'+n.id+'</td>'+
					'		<td>'+n.user.realName+'</td>'+
					'		<td>'+n.user.nickName+'</td>'+							
					'		<td>'+recoedType2+'</td>'+
					'		<td>'+n.money+'</td>'+
					'		<td>'+n.transactionNum+'</td>'+
					'		<td>'+moneyType2+'</td>'+
					'		<td>'+n.gmtDatetime+'</td>'+				
					'	</tr>';
					$('#thislist').append(thislist);		
				});
				$('#thiscount').text(data.total);
				$("#pager").pager({
					pagenumber: pageNo, 
					pagecount:data.data.pages,
					totalcount:data.data.total,
					buttonClickCallback: PageClick
				}); 
				
			} else if (data.code == 'OVERTIME'){
				var thisUrl = window.location.href;
				if (thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href="login.html";
				}

			} else {
				if (data.msg != '空数据') {
					alert(data.msg)
				}else{
					$('#thiscount').text(0);
				}
			}

		},
		error:function() {
			alert("error");
		}
	});	
	
    $.ajax({
        url: urlcore + "/api/user/account2Details?userId="+userId,
        type: "get",
        dataType: 'json',
        contentType: "application/json;charset=utf-8",
        success:function(data){
            if (data.success == true) {
                var da = data.data;
	                $('#allmoney').text(da.allmoney);
	                $('#depositmoney').text(da.depositmoney);          		           		
            } else if (data.code == 'OVERTIME'){
                    var thisUrl = window.location.href;
                    if (thisUrl.indexOf('login.html') <= -1) {
                        top.window.location.href="login.html";
                    }
                } else {
                    alert(data.msg);
                }
        },
        error:function() {
            /* Act on the event */
            alert("error");
        }
    });
    
    $.ajax({
        url: urlcore + "/api/cashRecord/moneySum?userId="+userId+"&startTime="+$('#startTime').val()+"&endTime="+$('#endTime').val()+"&value="+value,
        type: "get",
        dataType: 'json',
        contentType: "application/json;charset=utf-8",
        success:function(data){
            if (data.success == true) {
            	var da = data.data;
				if(JSON.stringify(da)=="{}"){
            		$('#sum').text(0);
            	}else{
            		$('#sum').text(data.data.sum);
            	}	
            } else if (data.code == 'OVERTIME'){
                    var thisUrl = window.location.href;
                    if (thisUrl.indexOf('login.html') <= -1) {
                        top.window.location.href="login.html";
                    }
                } else {
                    alert(data.msg);
                }
        },
        error:function() {
            /* Act on the event */
            alert("error");
        }
    });    
        
	

	
}

//回调函数  
PageClick = function(pageclickednumber) {  
    init(pageclickednumber); 
}
    
    

/**
 * 下拉框查询
 */
function searchEvent(){
	$("#change").change(function () {
		init(1);
	});
}
   
/**
 * 用户状态返回
 * @param {Object} recoedType
 */
function recoedTypeStr(recoedType){
	if (recoedType==1) {
		recoedType = '充值';
	}else if(recoedType==2) {
		recoedType = '提现';
	}
	else if(recoedType==3) {
		recoedType = '消费';
	}else if(recoedType==4) {
		recoedType = '收入';
	}else if(recoedType==5) {
		recoedType = '其他';
	}else if(recoedType==6) {
		recoedType = '奖惩';
	}
	return recoedType;
}

/**
 * 用户状态返回
 * @param {Object} moneyType
 */
function moneyTypeStr(moneyType){
	if (moneyType==1) {
		moneyType = '余额';
	}else if(moneyType==2) {
		moneyType = '押金';
	}
	return moneyType;
}


